package puzzle.masyu2.data;

import java.util.ArrayList;
import java.util.List;

import puzzle.common.point.Direction;
import tomoto.assertion.AssertUtil;

public class FlagHelper {
	private static final int[] NUMBER_OF_FLAGS = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };

	public static int getNumberOfFlags(int flags) {
		return NUMBER_OF_FLAGS[flags & 0x0f]; 
	}
	
	public static List<Direction> getDirectionsForFlags(int flags) {
		List<Direction> result = new ArrayList<Direction>();
		if ((flags & 0x01) != 0) result.add(Direction.N);
		if ((flags & 0x02) != 0) result.add(Direction.E);
		if ((flags & 0x04) != 0) result.add(Direction.S);
		if ((flags & 0x08) != 0) result.add(Direction.W);
		return result;
	}

	public static int getDirectionMask(Direction d) {
		switch (d) {
		case N:
			return 0x01;
		case E:
			return 0x02;
		case S:
			return 0x04;
		case W:
			return 0x08;
		default:
			throw AssertUtil.fail();
		}
	}

}
